from django.shortcuts import render
from django.views import View

from goods.models import GoodsCategory, GoodsChannel
from .models import ContentCategory, Content
from .utils import get_categories
# Create your views here.


class IndexView(View):

    def get(self,request):

        """提供首页广告界面"""
        contents = {}   # 装所有广告的字典
        """
        {
            'index_lbt': lbt_qs,
            'index_kx': kx_qs
        }
        """
        # 获取所有广告类别数据
        contentCategory_qs = ContentCategory.objects.all()
        for category in contentCategory_qs:
            contents[category.key] = category.content_set.filter(status=1).order_by('sequence')

        categories = get_categories()
        context = {
            'categories': categories,
            'contents': contents
        }


        return render(request, 'index.html', context)